﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.DependencyInjection;
using Volo.Abp.Modularity;

namespace EcoSystem.EntityFrameworkCore;

[DependsOn(
    typeof(EcoSystemDomainModule),
    typeof(AbpEntityFrameworkCoreModule)
)]
public class EcoSystemEntityFrameworkCoreModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        context.Services.AddAbpDbContext<EcoSystemDbContext>(options =>
        {
            /* Add custom repositories here. Example:
             * options.AddRepository<Question, EfCoreQuestionRepository>();
             */
            options.AddDefaultRepositories(true);

            Configure<AbpEntityOptions>(options =>
            {
                //配置一对多、一对多获取详情配置
                options.Entity<DictionaryItem>(DemandOrderOptions =>
                {
                    DemandOrderOptions.DefaultWithDetailsFunc = query => query.Include(o => o.Items);
                });
            });

            BaseEfCoreEntityExtensionMappings.Configure();

        });
    }
}
